<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<style>
    td, th {
        height: 34.29px !important;
    }

    .familyMemberDialog .modal-dialog {
        width: 60%;
    }

    input {
        height: 30px !important;
    }

    .editFormDiv label {
        margin: 0 auto !important;
    }

    .editFormDiv .control-label {
        text-align: right;
        line-height: 25px;
    }
</style>
<div class="row" style="margin-left: 0px!important;">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="margin-top: 15px">
        <div class="widget flat radius-bordered"
             style="margin-top: 0;box-shadow:0px 0px 10px rgba(122,161,184,0.3);!important;">
            <div class="widget-body no-padding">
                <div class="table-scrollable">
                    <!-- 数据表列信息列表 -->
                    <table class="table table-bordered dataTable">
                        <thead>
                        <tr>
                            <th title="费用类型">费用类型</th>
                            <th title="费用明细">费用明细</th>
                            <th title="报名状态">报名状态</th>
                            <th title="费用金额">费用金额</th>
                            <th title="课时数">课时数</th>
                            <th title="已消耗课次/课时">已消耗课次/课时</th>
                            <th title="原单价">原单价</th>
                            <th title="折后单价">折后单价</th>
                            <th title="购买时间">购买时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>${(data.paymentType???string(data.paymentType?html,"未设置"))!'未设置'}</td>
                            <td>${(data.packageName???string(data.packageName?html,"未设置"))!'未设置'}</td>
                            <td>${(data.applyStatus???string(data.applyStatus?html,"未设置"))!'未设置'}</td>
                            <td>${(data.sumPrice???string(data.sumPrice?html,"未设置"))!'未设置'}</td>
                            <td>
                                <#if data.type==1>
                                    ${(data.surplusFormalClassHour???string(data.surplusFormalClassHour?html,"未设置"))!'未设置'}
                                </#if>
                                <#if data.type==2>
                                    ${(data.surplusFormalAttendanceDay???string(data.surplusFormalAttendanceDay?html,"未设置"))!'未设置'}
                                </#if>
                            </td>
                            <td>
                                <#if data.type==1>
                                    ${(data.positiveConsumptionClassHour???string(data.positiveConsumptionClassHour?html,"未设置"))!'未设置'}
                                </#if>
                                <#if data.type==2>
                                    ${(data.positiveConsumptionAttendanceDay???string(data.positiveConsumptionAttendanceDay?html,"未设置"))!'未设置'}
                                </#if>
                            </td>
                            <td>
                                ${(data.originalUnitPrice???string(data.originalUnitPrice?html,"未设置"))!'未设置'}
                            </td>
                            <td>${(data.nowUnitPrice???string(data.nowUnitPrice?html,"未设置"))!'未设置'}</td>
                            <td>${(data.createTime???string(data.createTime?html,"未设置"))!'未设置'}</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <form class="editForm editFormDiv" action="${saveUrl}" method="post" responseType="JSON" role="form"
              id="editForm_${serializeNum}" data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
              data-bv-message="This value is not valid"
              data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
              data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
              data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
            <input type="hidden" id="paymentId" name="paymentId" value="${data.id}">
            <input type="hidden" id="stuId" name="stuId" value="${stuId}">
            <input type="hidden" id="packageId" name="packageId" value="${packageId}">
            <input type="hidden" id="refundType" name="refundType" value="${refundType}">
            <input type="hidden" id="paymentType" name="paymentType" value="${data.paymentType}">
            <input type="hidden" id="type" name="type" value="${data.type}"/>
            <!-- 剩余正天(正)-->
            <input type="hidden" id="surplusFormalAttendanceDay" name="surplusFormalAttendanceDay"
                   value="${data.surplusFormalAttendanceDay}"/>
            <!-- 剩余正课时(正)-->
            <input type="hidden" id="surplusFormalClassHour" name="surplusFormalClassHour"
                   value="${data.surplusFormalClassHour}"/>
            <!-- 已消耗出勤天数(正)-->
            <input type="hidden" id="positiveConsumptionAttendanceDay" name="positiveConsumptionAttendanceDay"
                   value="${data.positiveConsumptionAttendanceDay}"/>
            <!-- 已消耗课时数(正)-->
            <input type="hidden" id="positiveConsumptionClassHour" name="positiveConsumptionClassHour"
                   value="${data.positiveConsumptionClassHour}"/>
            <!-- 未消耗出勤天数(正)-->
            <input type="hidden" id="positiveUnusedAttendanceDay" name="positiveUnusedAttendanceDay"
                   value="${data.positiveUnusedAttendanceDay}"/>
            <!-- 未消耗课时数(正)-->
            <input type="hidden" id="positiveUnusedClassHour" name="positiveUnusedClassHour"
                   value="${data.positiveUnusedClassHour}"/>
            <input type="hidden" id="originalUnitPrice" name="originalUnitPrice" value="${data.originalUnitPrice}"/>
            <input type="hidden" id="nowUnitPrice" name="nowUnitPrice" value="${data.nowUnitPrice}"/>
            <input type="hidden" id="sumPrice" name="sumPrice" value="${data.sumPrice}"/>
            <div>
                <div class="col-xs-12 col-sm-6 col-lg-12 nopadding-left nopadding-right" style="margin-bottom: 15px">
                    <div class="form-group">
                        <div class="col-xs-6">
                            <label for="classHour"
                                   class="col-xs-2 control-label no-padding-right no-padding-left"><span style="color: red">*</span>退课时数：</label>
                            <label class="col-xs-3 no-padding-right no-padding-left">
                                <input data-bv-integer-message="The field is number"
                                       data-bv-message="The field is not valid"
                                       data-bv-integer="true" size="11" name="classHour" id="classHour" alt="退课时数"
                                       placeholder="退课时数"
                                       type="text" title="退课时数" class="form-control" value="${editEntity.amount}"
                                       onblur="refundAmount(this)"/>
                                <span class="text"></span>
                            </label>
                            <label for="classHour" class="col-xs-7 control-label no-padding-right no-padding-left text-align-left" style="padding-left: 5px!important;">*可退课时数：
                                    <span style="color: red">
                                        <#if data.type == 1>
                                        ${data.surplusFormalClassHour}
                                    </#if>
                                    <#if data.type == 2>
                                        ${data.surplusFormalAttendanceDay}
                                    </#if>
                                    </span>
                                课/次（不含赠课）
                            </label>
                            <!--<label for="classHour" class="col-sm-3 control-label no-padding-right">退课时数：${surplusFormalClassHour}课/次（不含赠课）</label>-->
                        </div>
                        <div class="col-xs-6">
                            <label>
                                <input name="retirement" id="retirement" type="checkbox" value="1"
                                       onclick="CalculateRetirement(this)"
                                       style="position: static;opacity: 1">
                            </label>
                            <label style="color: red">
                                一键退班（勾选此按钮，点击提交后将自动退班）
                            </label>
                        </div>
                    </div>
                </div>


                <div class="col-xs-6 col-sm-6 col-lg-12" style="margin-bottom: 20px">
                    <div class="col-xs-6 nopadding-left">
                        <div class="form-group">
                            <label for="amout" title="默认退费金额=课时包金额-（正课课时数-退课课时数）*原单价"
                                   class="col-xs-2 control-label no-padding-right no-padding-left"><span style="color: red">*</span>退费金额：</label>
                            <label class="col-xs-6 no-padding-right no-padding-left">
                                <input data-bv-integer-message="The field is number"
                                       data-bv-message="The field is not valid"
                                       data-bv-integer="true" size="11" name="amout" id="amout" alt="退费金额"
                                       placeholder="退费金额"
                                       type="text" title="退费金额" class="form-control col-xs-12" value="${editEntity.amount}"/>
                                <span class="text"></span>
                            </label>
                        </div>
                    </div>
                </div>

                <div class="col-xs-6 col-sm-6 col-lg-12" style="margin-bottom: 20px">
                    <div class="col-xs-6 nopadding-left">
                        <div class="form-group">
                            <label for="amout" title="默认退费金额=课时包金额-（正课课时数-退课课时数）*原单价"
                                   class="col-xs-2 control-label no-padding-right no-padding-left"><span style="color: red">*</span>退费备注：</label>
                            <label class="col-xs-10 no-padding-right no-padding-left">
                               <textarea class="form-control" name="remark" size="500" rows="4" style="resize:none" id="remark"
                                         value="${editEntity.remark}"></textarea>
                            </label>
                        </div>
                    </div>
                </div>

                <div class="col-xs-12" style="margin-bottom: 10px">
                    <div class="text-align-center">
                        <button style="width: 80px;margin-right: 20px" type="button" class="btn btn-blue"
                                id="depositEditFormSubmitBtn_${serializeNum}" onclick="Refund()">提交
                        </button>
                        <input style="width: 80px" type="button" class="btn btn-blue" data-dismiss="modal" value="取消"/>
                    </div>
                </div>
            </div>
        </form>
    </div>

</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>


    function refundAmount(that) {
        var classHour = $(that).val();
        var type = $('.type').val();
        var surplusFormalAttendanceDay = $('.surplusFormalAttendanceDay').val();
        var surplusFormalClassHour = $('.surplusFormalClassHour').val();
        var positiveConsumptionAttendanceDay = $('.positiveConsumptionAttendanceDay').val();
        var positiveConsumptionClassHour = $('.positiveConsumptionClassHour').val();
        var originalUnitPrice = $('.originalUnitPrice').val();
        var sumPrice = $('.sumPrice').val();
        var sum = 0;
        var canRefunded = 0;
        if (type == 1) {
            canRefunded = sumPrice - (positiveConsumptionClassHour * originalUnitPrice);
            sum = (canRefunded / surplusFormalClassHour) * classHour;
        }
        if (type == 2) {
            canRefunded = sumPrice - (positiveConsumptionAttendanceDay * originalUnitPrice);
            sum = (canRefunded / surplusFormalAttendanceDay) * classHour;
        }
        console.log(classHour);
        console.log(type);
        console.log(surplusFormalAttendanceDay);
        console.log(surplusFormalClassHour);
        console.log(positiveConsumptionAttendanceDay);
        console.log(positiveConsumptionClassHour);
        console.log(originalUnitPrice);
        console.log(canRefunded);
        console.log(sum);

        $('#amout').val(sum);

    }

    /**
     * 提交
     * @param that
     * @constructor
     */
    function Refund() {
        var paymentId = $("#paymentId").val();
        var stuId = $("#stuId").val();
        var packageId = $("#packageId").val();
        var refundType = $("#refundType").val();
        var type = $("#type").val();
        var classHour = $("#classHour").val();
        var amout = $("#amout").val();
        var remark = $("#remark").val();
        var retirement = $("#retirement").val();
        ajaxRequest("tssMemberReturnPremiumController/saveOrUpdate.do", {
            paymentId: paymentId,
            stuId: stuId,
            packageId: packageId,
            refundType: refundType,
            type: type,
            classHour: classHour,
            amout: amout,
            remark: remark,
            retirement: retirement
        }, function (data) {
            alert("提交成功");
            if (data.resCode == "200") {

            }
            alert(data.resMsg)
        }, function () {
            ajaxError("加载页面失败!")
        }, "post", "json")

    }

    //点击一键退班
    function CalculateRetirement(that) {
        var val = $(that).prop("checked");
        if (val) {

        }
    }

</script>